<script setup>

import Login from "@/view/Login.vue";
import {globalStore} from "@/assets/store-index.js";
import {onMounted} from "vue";


const gs = globalStore()

const init = () => {
  const token = localStorage.getItem("token")
  if (token){
    gs.isLogin = true;
    gs.token = token;
  }
}
const logout = () => {
  localStorage.removeItem("token");
  gs.isLogin = false;
}

onMounted( init)

</script>

<template>
  <div v-if="gs.isLogin">
    <div class="top">
      <div>
        <img src="/logo.png" alt="" style="height: 40px;">
        <span style="font-size: 1.25rem">智慧校园管理系统</span>
      </div>

      <div>
        <el-button  @click="logout">退出</el-button>
      </div>
    </div>

    <div class="content">
      <div class="left" style="width: 130px">
        <el-menu style="height: calc(100vh - 80px);" router default-active="/">
          <el-menu-item index="/"><el-icon><House /></el-icon>主页</el-menu-item>
          <el-menu-item index="/student"><el-icon><User /></el-icon>学员管理</el-menu-item>
          <el-menu-item index="/dormitory"><el-icon><School /></el-icon>寝室管理</el-menu-item>
          <el-menu-item ><el-icon><KnifeFork /></el-icon>食堂管理</el-menu-item>
          <el-menu-item ><el-icon><Reading /></el-icon>课程管理</el-menu-item>
        </el-menu>
      </div>
      <div class="right" style="flex-grow: 1">
          <RouterView />
      </div>
    </div>
  </div>

  <div v-if="!gs.isLogin">
    <Login />
  </div>

</template>

<style scoped>
  .top{
    top: 50px;
    padding: 5px 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #dadada;
    margin-bottom: 10px;
  }
  .content{
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.5rem;
  }
</style>
